<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // Promise.resolve();   快速生成一个fullfilled状态的 Promise实例，并将传入的参数作为回调函数的返回值
    // Promise.reject();    快速生成一个rejected状态的 Promise实例，并将传入的参数作为回调函数的返回值

    var p = new Promise(function(resolve,reject) {
        // resolve(1);
        reject(0);
    });
    console.log(p);

    // 等同于
        console.log(Promise.reject(0));
        console.log(Promise.resolve(1));



    // 接收一个对象，对象里面是then方法
        var p = Promise.resolve({
            then:function(resolve,reject) {
                var num = Math.random();
                if(num > 0.5) {
                    resolve(num);
                } else {
                    reject(num);
                }
            },            
        })
        console.log(p);

        p.then(function(res){
            console.log(res);
        }).catch(function(res){
            console.log(res);
        })
</script>
</html>